#include "input.h"

#include "voxel.h"
#include "volume.h"

#include <fstream>
#include <iostream>


namespace Splatit {
	
	
Input::Input(const char* _filename) : filename(_filename) { }
	
Volume* Input::load(unsigned int width,unsigned int height, unsigned int depth) const {
	//cria o volume
	Voxel*** voxels = new Voxel**[width];
	for(unsigned int i = 0; i < width; i++) {
		voxels[i] = new Voxel*[height];
		for(unsigned int j = 0; j < height; j++)
			voxels[i][j] = new Voxel[depth];
	}
	
// 	std::cout << "lalalal" << std::endl;
	std::ifstream fin;
	fin.open(filename);
	
	unsigned short hist[255];
	//inicializa
	for (unsigned int z=0;z<depth;z++){
	for (unsigned int y=0;y<height;y++){
	for (unsigned int x=0;x<width;x++) {
		char c;
		fin.get(c);
		c = (unsigned char) c;
		hist[c]++;
		voxels[x][y][z] = Voxel(Vector(x,y,z),c);
// 		std::cout << "c:" << c << "  " << std::endl;
	}
	}
	}
	

	fin.close();
	return new Volume(voxels,width,height,depth);
}
	
	
	
}
